var TransitBase = require('geoTransitBase');
var Tween = require('geoTweenMoveTo');
cc.Class({
    extends: TransitBase,

    properties: {
        startNode: {
            default: null,
            type: cc.Node,
            tooltip: '开始位置'
        },
        enterNode: {
            default: null,
            type: cc.Node,
            tooltip: '入场位置'
        },
        leaveNode: {
            default: null,
            type: cc.Node,
            tooltip: '出场位置'
        },
        enterDuration: {
            default: 0.3,
            type: cc.Float,
            tooltip: '入场时长'
        },
        leaveDuration: {
            default: 0.3,
            type: cc.Float,
            tooltip: '出场时长'
        },
        usePosition: true,
        useRotation: false,
        useScale: false,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },

    enter(complete) {
        var tween = this._getTween();
        // 设置到开始点
        tween.setToNode(this.startNode, this.usePosition, this.useScale, this.useRotation);
        //
        tween.doTweenToNode(this.enterNode, this.enterDuration,
            this._super.bind(this, complete),
            this.usePosition, this.useScale, this.useRotation);
    },

    leave(complete) {
        var tween = this._getTween();
        //
        tween.doTweenToNode(this.leaveNode, this.leaveDuration,
            this._super.bind(this, complete),
            this.usePosition, this.useScale, this.useRotation);
    },

    _getTween() {
        var tween = this.target.getComponent(Tween);
        if (tween == null) tween = this.target.addComponent(Tween);
        //
        return tween;
    }

    // update (dt) {},
});
